﻿var left_condition = "";

_myDataTable = null;
function fnSearch(o) {
    var key = window.document.getElementById("keyword").value;
    var requestStr = "entity=V_SetTableList&condition=" + encodeURI("TableName='" + const_LeftTable + "' ") + "&output=json&r=" + Math.random() + "&customCondition=Caption like '%" + encodeURI(key) + "%'";
    _myDataTable.requery(requestStr);
}


function InitLeftData() {
    YAHOO.example.EHR_JSON = function () {
        var myColumnDefs = [{ key: 'Caption', label: '标题', sortable: true}];
        var myDataSource = new YAHOO.util.DataSource("AjaxData/JSONList.aspx?");
        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
        myDataSource.connXhrMode = "queueRequests";
        myDataSource.responseSchema = {
            resultsList: "rows",
            fields: ["Key", "Caption"]
        };
        this.myDataTable1 = new YAHOO.widget.ScrollingDataTable("leftgrid", myColumnDefs,
                    myDataSource, { initialRequest: "entity=V_SetTableList&condition=" + encodeURI("TableName='" + const_LeftTable + "' ") + "&output=json&r=" + Math.random() + "", selectionMode: "single", height: (const_height) + "px" });
        var mySuccessHandler = function () {
            this.set("sortedBy", null);
            this.onDataReturnAppendRows.apply(this, arguments);
        };
        _myDataTable = this.myDataTable1;
        var myFailureHandler = function () {
            this.showTableMessage(YAHOO.widget.DataTable.MSG_ERROR, YAHOO.widget.DataTable.CLASS_ERROR);
            this.onDataReturnAppendRows.apply(this, arguments);
        };

        var mySuccessHandlers = function () {
            mySuccessHandler();
            var recs = myDataTable1.getRecordSet();
            if (recs._records.length > 0) {
                LoadData(recs._records[0]._oData["Key"]);
            }
        };
        var callbackObj = {
            success: mySuccessHandlers,
            failure: myFailureHandler,
            scope: myDataTable1
        }
        //var pId;
        var OnRowSelected = function () {
            var recordID = myDataTable1.getSelectedRows()[0];
            record = myDataTable1.getRecord(recordID);
            ParentID = record.getData("Key");
            //alert(ParentID);

            const_CustomCondition = const_ForeignKey + window.decodeURI("='" + ParentID + "'");
            initialRequestUrl = "pageindex=1&entity=" + const_entityName + "&order=" + const_Order + "&r=" + Math.random() + "&zip=94089&results=10&output=json&functionid=" + const_functionId + "&customCondition=" + decodeURI(const_CustomCondition),
            BindData();
            GetTotal("AjaxData/JsonList.aspx?onlyTotal=true&" + initialRequestUrl);

        };
        // 调用自定义双击行的方法
        var onRowDoubleClick = function () {
            //alert('1');
            if (typeof (CustomDbClick) == "function") {
                CustomDbClick();
            }
        };
        // Subscribe to events for row selection 
        this.myDataTable1.subscribe("rowMouseoverEvent", this.myDataTable1.onEventHighlightRow);
        this.myDataTable1.subscribe("rowMouseoutEvent", this.myDataTable1.onEventUnhighlightRow);
        this.myDataTable1.subscribe("rowClickEvent", this.myDataTable1.onEventSelectRow);
        this.myDataTable1.subscribe("rowClickEvent", OnRowSelected);
        this.myDataTable1.subscribe("rowDblclickEvent", onRowDoubleClick);
        // Programmatically select the first row 
        this.myDataTable1.selectRow(this.myDataTable1.getTrEl(0));
        //var hideid= function(){ this.myDataTable.hideColumn(parseInt(0)); this.myDataTable.refreshView(); };
        //hideid();


    } ();
}